﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BusinessObjects;
using DataAccess;

namespace QuanLyHopDong
{
    public partial class GiangVienThinhGiangListView : Form
    {
        private BindingList<GiangVienThinhGiang> bindingListGiangVienThinhGiang;
        private GiangVienThinhGiang _giangVienThinhGiang;

        public GiangVienThinhGiangListView()
        {
            InitializeComponent();
        }

        private void GiangVienThinhGiangListView_Load(object sender, EventArgs e)
        {
            string[] listFieldName = new string[] { "MaQuanLy", "Ho", "Ten", "GioiTinh", "NgaySinh", "NoiSinh", "QueQuan", "BoPhan.TenBoPhan", "TinhTrang.TenTinhTrang", "CoQuanCongTac" };
            string[] listColumnName = new string[] { "Mã quản lý", "Họ", "Tên", "Giới tính", "Ngày sinh", "Nơi sinh", "Quê quán", "Bộ Phận", "Tình Trạng", "Cơ Quan Công Tác" };
            AppGridView.InitGridView(gvGiangVienThinhGiang, false, false, DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.RowSelect, false, false, false, true);
            AppGridView.ReadOnlyGridView(gvGiangVienThinhGiang);
            AppGridView.ShowField(gvGiangVienThinhGiang, listFieldName, listColumnName);

            bindingListGiangVienThinhGiang = new BindingList<GiangVienThinhGiang>(DataAccessObject.GiangVienThinhGiang.GetListGiangVienThinhGiang());

            bindingSourceGiangVienThinhGiang.DataSource = bindingListGiangVienThinhGiang;
            gvGiangVienThinhGiang.Invalidate();
        }

        private void gcGiangVienThinhGiang_DoubleClick(object sender, EventArgs e)
        {
            _giangVienThinhGiang = gvGiangVienThinhGiang.GetFocusedRow() as GiangVienThinhGiang;
            OpenDetailForm();
        }

        private void btnThem_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            _giangVienThinhGiang = new GiangVienThinhGiang();
            OpenDetailForm();
        }

        private void OpenDetailForm()
        {
            
            GiangVienThinhGiangDetailView detailView = new GiangVienThinhGiangDetailView(_giangVienThinhGiang);
            detailView.SaveChanged += new EventHandler(detailView_SaveChanged);
            detailView.MdiParent = this.MdiParent;
            detailView.Show();
            
        }

        void detailView_SaveChanged(object sender, EventArgs e)
        {
            gvGiangVienThinhGiang.Invalidate();
        }

        private void btnDong_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.Close();
        }
    }
}
